﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class ListQuanHuyen : System.Web.UI.UserControl
    {
        public int count;
        public string name;
        public DataTable dt;
        ListItem lt;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Them du lieu vao cat 1      
                count = 1;

                Cate1.Items.Clear();
                dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTable("tbl_TinhThanhPho");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    lt = new ListItem(dt.Rows[i]["TinhThanhPho_Ten"].ToString(), dt.Rows[i]["TinhThanhPho_ID"].ToString());
                    Cate1.Items.Add(lt);
                }
                int id = Convert.ToInt32(Cate1.SelectedValue);
                dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_QuanHuyen", "TinhThanhPho_ID", id.ToString());
                rpt_DonVi.DataSource = dt;
                rpt_DonVi.DataBind();
            }

        }

        protected void Cate1_SelectedIndexChanged(object sender, EventArgs e)
        {
            count = 1;
            int id = Convert.ToInt32(Cate1.SelectedValue);
            dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_QuanHuyen", "TinhThanhPho_ID", id.ToString());
            rpt_DonVi.DataSource = dt;
            rpt_DonVi.DataBind();

        }


        protected void rpt_DonVi_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                DAL.DCollector.DBCollector.Instance.StoredProcedureDeleteByRows("tbl_QuanHuyen", "QuanHuyen_ID", id.ToString());
                Response.Redirect("/Admin/Index.aspx?panel=1&sub=12");
            }
        }
    }
}